<template>
  <div>
    <!-- 分类列表 -->
    <el-tabs v-model="itemId" @tab-click="getPhotoList(itemId)">
      <el-tab-pane
        v-for="item in CateList"
        :label="item.title"
        :key="item.id"
        :name="item.id + ''"
      >
      </el-tab-pane>
    </el-tabs>

    <!-- 图片列表 -->
    <div class="demo-image__lazy">
      <ul>
        <router-link v-for="item in photoList" :key="item.id" :to="'/home/photoinfo/' + item.id" tag="li">
          <img v-lazy="item.img_url" />
          <div class="info">
            <div class="info-title">{{ item.title}}</div>
            <div class="info-body">{{ item.zhaiyao }}</div>
          </div>
        </router-link>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      CateList: [],
      photoList: [],
      itemId: 0,
    };
  },
  created() {
    this.getImgCategory();
    this.getPhotoList(0);
  },
  methods: {
    getImgCategory() {
      this.$http.get("api/getimgcategory").then((result) => {
        if (result.body.status === 0) {
          result.body.message.unshift({ title: "全部", id: 0 });

          this.CateList = result.body.message;
        }
      });
    },

    getPhotoList(itemid) {
      this.$http.get("api/getimages/" + itemid).then((result) => {
        if (result.body.status === 0) {
          this.photoList = result.body.message;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.demo-image__lazy {
  ul {
    list-style: none;
    padding: 0;
    margin-top: -8px;
  }

  li {
    padding: 8px;
    position: relative;
  }

  img {
    width: 100%;
    box-shadow: 0 0 10px darkgray;
  }

  .info{
    color: white;
    max-height: 80px;
    position: absolute;
    bottom: 8px;
    background: rgba($color: #000000, $alpha: 0.4);
  }
  
  .info-title{
    font-size: 13px;    
  }

   .info-body{
    font-size: 12px;    
  }
}
</style>